package com.example.constellation.Adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.constellation.R;
import com.example.constellation.bean.YsitemBean;

import java.util.List;

public class fg3listadapter extends BaseAdapter {
    private Context context;
    private List<YsitemBean> mdatas;

    public fg3listadapter(Context context, List<YsitemBean> mdatas) {
        this.context = context;
        this.mdatas = mdatas;
    }

    @Override
    public int getCount() {
        return mdatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mdatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewholder holder=null;
        if (convertView==null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.fg3listitem,null);
            holder=new viewholder(convertView);
            convertView.setTag(holder);
        }else {
            holder= (viewholder) convertView.getTag();
        }
        YsitemBean bean = mdatas.get(position);
        holder.fg3listtitle.setText(bean.getTitle());
        holder.fg3listcontent.setText(bean.getContent());
        GradientDrawable background = (GradientDrawable) holder.fg3listtitle.getBackground();
        background.setColor(bean.getColor());
        return convertView;
    }

    class viewholder{
        TextView fg3listtitle,fg3listcontent;
        public viewholder(View view){
            fg3listtitle=view.findViewById(R.id.fg3listtitle);
            fg3listcontent=view.findViewById(R.id.fg3listcontent);
        }
    }
}
